layui.define(["layer", "form"], function(a) {
    layui.layerform = layui.form()
});
var login_form = function(a) {
    var b = $("#popup-captcha");
    a.onSuccess(function() {
        Aform("login", $("form").serialize(), function(c) {
            if (1 != c.state) return b.hide(), a.reset(), Rs(c), !1;
            parent.UCheck(0 < $('input[name="uclick"]').length ? parent.layer.getFrameIndex(window.name) : "")
        })
    });
    $("#login_submit_button").click(function() {
        if ("phone" != $("input[name=login]").val()) {
            var c = $("input[name=login_name]"),
                d = $("input[name=login_pass]");
            if (!/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/.test(c.val()) && !/^1[3|4|5|6|7|8|9][0-9]\d{8}$/.test(c.val())) return layer.tips("\u8bf7\u8f93\u5165\u6b63\u786e\u7684\u90ae\u7bb1\u6216\u624b\u673a\u53f7",
                c, {
                    tips: 1
                }), !1;
            if (6 > d.val().length) return layer.tips("\u8bf7\u8f93\u5165\u6b63\u786e\u7684\u5bc6\u7801(6-20\u4f4d)", d, {
                tips: 1
            }), !1
        } else {
            c = $("input[name=login_phone]");
            d = $("input[name=vcode]");
            if (11 != c.val().length) return layer.tips("\u8bf7\u8f93\u5165\u6b63\u786e\u7684\u624b\u673a\u53f7\u7801\uff01", c, {
                tips: 1
            }), !1;
            if (4 != d.val().length) return layer.tips("\u624b\u673a\u9a8c\u8bc1\u7801\u9519\u8bef\uff0c\u8bf7\u91cd\u65b0\u8f93\u5165\uff01", d, {
                tips: 1
            }), !1
        } if (b.is(":visible") && !a.getValidate()) return layer.tips("\u8bf7\u5148\u5b8c\u6210\u9a8c\u8bc1",
            b, {
                tips: 1
            }), !1;
        b.show()
    });
    a.appendTo(b)
};

function logingt() {
    $.getScript("https://static.geetest.com/static/tools/gt.js", function() {
        $.ajax({
            url: "/html/StartCaptchaServlet?t=" + (new Date).getTime(),
            type: "get",
            dataType: "json",
            success: function(a) {
                initGeetest({
                    gt: a.gt,
                    challenge: a.challenge,
                    new_captcha: a.new_captcha,
                    product: "custom",
                    width: $("#login_submit_button").parent().width() + "px",
                    next_width: "278px",
                    area: "#logingt",
                    bg_color: "#fff",
                    offline: !a.success
                }, login_form)
            }
        })
    })
}
Aform = function(a, b, c, d) {
    $.ajax({
        type: "POST",
        url: "/aform/index/" + a,
        async: d || !1,
        data: b,
        dataType: "json",
        success: function(a) {
            c ? c(a) : Rs(a)
        },
        error: function() {
            layer.closeAll("loading");
            layer.msg("\u7f51\u7edc\u5f02\u5e38\uff0c\u8bf7\u91cd\u8bd5\uff01");
            return !1
        }
    })
};
sendbtn = function(a, b) {
    if (11 != $("input[name=login_phone]").val().length) return layer.tips("\u8bf7\u8f93\u5165\u6b63\u786e\u7684\u624b\u673a\u53f7\u7801\uff01", $("input[name=login_phone]"), {
        tips: [3, "#f90"]
    }), $("input[name=login_phone]").focus(), !1;
    $(a).attr("disabled", !0);
    Aform("sendinfo", $("form").serialize(), function(c) {
        -1 == c.state ? sendtime(a, b) : $(a).attr("disabled", !1);
        Rs(c)
    })
};
sendtime = function(a, b) {
    function c(b) {
        return function() {
            if (b == d) $(a).removeClass("layui-btn-disabled"), $(a).val("\u83b7\u53d6\u9a8c\u8bc1\u7801"), $(a).attr("disabled", !1);
            else {
                var c = d - b;
                $(a).val(c + "\u79d2\u540e\u91cd\u65b0\u53d1\u9001")
            }
        }
    }
    var d = b || 60;
    $(a).attr("disabled", !0);
    $(a).val(d + "\u79d2\u540e\u91cd\u65b0\u53d1\u9001").addClass("layui-btn-disabled");
    for (b = 1; b <= d; b++) setTimeout(c(b), 1E3 * b)
};
Rs = function(a) {
    layer.closeAll("loading");
    switch (a.state) {
        case -1:
            layer.tips(a.info, a.element, {
                tips: [a.tips || 1, a.color || "#f90"],
                time: a.time || 4E3
            });
            $(a.element).val("").focus();
            a.fun && eval(a.fun);
            break;
        case -2:
            layer.confirm(a.info || "\u767b\u5f55\u5931\u6548\uff0c\u8bf7\u91cd\u65b0\u767b\u5f55\uff01", {
                icon: a.icon || 8,
                btn: [a.btn1 || "\u767b\u9646", a.btn2 || "\u53d6\u6d88"]
            }, function(b) {
                a.url ? location.href = a.url : layer_login();
                layer.close(b)
            }, function(a) {
                layer.close(a)
            });
            a.fun && eval(a.fun);
            break;
        case -3:
            a.fun &&
                eval(a.fun);
            break;
        case 301:
            location.href = a.url;
            break;
        default:
            a.clear || layer.alert(a.info, {
                icon: a.state
            }, function(b) {
                a.fun ? eval(a.fun) + layer.close(b) : a.url ? 1 == a.url ? location.reload() : location.href = a.url : a.element ? $(a.element).val("").focus() + layer.close(b) : layer.close(b)
            })
    }
};
$(function() {
    //document.domain = "mafabu.com";
    logingt();
    $(".three-login a").click(function() {
        var a = $(this).attr("id");
        if ("qq" == a || "baidu" == a) var b = 720,
            c = 450;
        else b = "sina" == a ? 770 : "alipay" == a ? 420 : 570, c = 530;
        window.open("/oauth/login/" + a, $(this).attr("title"), "width=" + b + ",height=" + c + ",top=" + ((window.screen.availHeight - 30 - c) / 2) + ",left=" + ((window.screen.availWidth - 10 - b) / 2) + ",menubar=0,scrollbars=1,resizable=1,status=1,titlebar=0,toolbar=0,location=1")
    });
    $(".login_type a").click(function() {
        var a = $(this).data("login"),
            b = $("input[name=login_name]").val(),
            c = $("input[name=login_" + a + "]").val();
        $(this).addClass("curr").siblings().removeClass("curr");
        $(".login_box:eq(" + $(this).index() + ")").removeClass("hide").siblings(".login_box").addClass("hide");
        $("input[name=login]").val(a);
        "phone" != a || "" != c || 11 != b.length || isNaN(b) || (c = b);
        $("input[name=login_" + a + "]").val("").focus().val(c)
    });
    $(".RememberMe label").click(function() {
        $(this).toggleClass("IChecked");
        $("input[name=RememberMe]").val($(this).hasClass("IChecked") ? 1 : 0)
    })
});